package cn.coco.jf.fw.api.resp;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * 2018-05-03后不推荐使用
 * 预计2.0版本开始废弃
 * @author mark
 *
 */
@Deprecated
public class ApiRespJson{
    private JSONObject respJson = new JSONObject();
    private JSONObject dataJson = new JSONObject();
    
    private final static int CODE_ERROR_REQUIRE = 700;
    private final static int CODE_ERROR_SYSTEM = 500;
    private final static int CODE_SUCCESS = 200;
    private final static String MSG_SUCCESS = "OK";
    
    public JSONObject toRespErrorSystem(){
        respJson.put("code", CODE_ERROR_SYSTEM);
        return respJson;
    }
    
    public JSONObject toRespErrorRequire(){
        respJson.put("code", CODE_ERROR_REQUIRE);
        return respJson;
    }
    
    public JSONObject toRespError(int code){
        respJson.put("code", code);
        return respJson;
    }

    public JSONObject toRespSuccess(){
        respJson.put("code", CODE_SUCCESS);
        respJson.put("msg", MSG_SUCCESS);
        respJson.put("data", dataJson);

        return respJson;
    }
    
    public JSONObject toResp(){
        return respJson;
    }
    
    public JSONObject dataAttrArr(String attr, JSONArray arr){
        dataJson.put(attr, arr);
        return dataJson;
    }
    
    public JSONObject dataAttrObject(String attr, Object val){
        dataJson.put(attr, val);
        return dataJson;
    }
    
    public JSONObject dataAttr(String attr, Integer val){
        dataJson.put(attr, val);
        return dataJson;
    }
    
    public JSONObject dataAttr(String attr, String val){
        dataJson.put(attr, val);
        return dataJson;
    }


}
